#define  __rem_c

#include "includeAll.h"


void rem_invalid(void)
{
   TR1=0;
   TF1=0;
   d_rem_step=0;
}

void remControl()
{
  
   TR1=0;//                                  T1停止
   TF1=0;
   d_th1_tmp=TH1;//                          暂存数据
   switch(d_rem_step)
   {
      case(0):
      {
         TL1=(65536-c_t1_value_15ms)%256;
         TH1=(65536-c_t1_value_15ms)/256;
         TR1=1;                              //T1启动
         d_rem_step=1;
         break;
      }
      case(1):
      {
         TL1=(65536-c_t1_value_3ms)%256;
         TH1=(65536-c_t1_value_3ms)/256;
         TR1=1;//                            T1启动
         d_rem_bit_count=32;
         d_rem_step=2;//                     引导头12~15ms ok
         if(d_th1_tmp<((65536-c_t1_value_3ms)/256))   rem_invalid();//引导头<12ms 出错
         break;
      }
      case(2):
      {
         TL1=(65536-c_t1_value_3ms)%256;
         TH1=(65536-c_t1_value_3ms)/256;//   准备接收下一位
         TR1=1;//                            T1启动
         d_rem_addr<<=1;
         if(d_rem_data|bit15) d_rem_addr|=bit1;
         else                 d_rem_addr&=~bit1;
         d_rem_data<<=1;
         if(d_th1_tmp>=((65536-c_t1_value_1313us)/256))  d_rem_data|=bit1;
         else                                            d_rem_data&=~bit1;
         if(--d_rem_bit_count==0)
         {
            rem_invalid();
           if(d_rem_addr==0xffff/* && (d_rem_data_h+d_rem_data_l)==0xff*/)
            {
               d_rem_key=d_rem_data>>8;
			  if(d_rem_key==0)
			  {
				   d_rem_key=0xff;
			  }
            }
         }
         break;
      }
      default: break;
   }
}
